package com.yawn.demomybatis.dao;

import com.yawn.demomybatis.entity.Person;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PersonDao {

    @Select("select * from person where id=#{id}")
//    @ResultType(Person.class)
    @ResultMap("personMap")
    Person get(@Param("id") String id);

    @Select("select * from person")
    @Results(id = "personMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "nickName", column = "name"),
            @Result(property = "age", column = "age")
    })
    List<Person> list();

    // name 和 age 必须是Person对象的属性才可以
    @Insert("insert into person(name, age) value(#{name}, #{age})")
    int add(Person person);
}
